package View;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import Controller.Tasker;
import Events.GenericEvent;


public class PopUp implements ActionListener 
{
	private GenericEvent event;
	private JFrame frame;
	private ContentView cv;
	private Tasker tk;
    private String dir = "images/";
	
	public PopUp(GenericEvent event, ContentView cv, Tasker tk)
	{
		this.event= event;
		this.cv= cv;
		this.tk = tk;
		
		createFrame();
	}
	
	public void createFrame()
	{
		frame = new JFrame("Reminder ...");
		frame.setSize(new Dimension(500,300));
		frame.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		JLabel img = new JLabel();
		img.setPreferredSize(new Dimension(490,280));
		img.setIcon(new ImageIcon(dir+"fondoreminder.png"));
		img.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		JLabel font = new JLabel();
		font.setPreferredSize(new Dimension(470,280));
		font.setLayout(new FlowLayout(FlowLayout.CENTER,30,12));
		
		JLabel emp = new JLabel();
		if(event.getType()==0)
			emp.setText("Appointment");
		else if(event.getType()==1)
			emp.setText("Alarm");
		else
			emp.setText("Task");
		emp.setFont(new Font("Corbel", Font.BOLD, 30));
		emp.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		emp.setVerticalAlignment(javax.swing.SwingConstants.TOP);
		emp.setForeground(Color.GRAY);
		emp.setPreferredSize(new Dimension(490,80));
		
		JLabel emp2 = new JLabel();
		emp2.setPreferredSize(new Dimension(490,10));
		
		JLabel icon = new JLabel();
		if(event.getType()==0)
			icon.setIcon(new ImageIcon(dir+"2icon0.png"));
		else if(event.getType()==1)
			icon.setIcon(new ImageIcon(dir+"2icon1.png"));
		else
			icon.setIcon(new ImageIcon(dir+"2icon2.png"));
		icon.setPreferredSize(new Dimension(60,60));
		
		
		JLabel subject = new JLabel("<html>"+event.getSubject()+"</html>");
		subject.setPreferredSize(new Dimension(350,60));
		subject.setFont(new Font("Corbel", Font.BOLD, 23));
		
		JButton bt = new JButton();
		bt.setContentAreaFilled(false);
		bt.setBorderPainted(false);
		bt.setIcon(new ImageIcon(dir+"snooze.png"));
		bt.setPreferredSize(new Dimension(150,40));
		bt.addActionListener(this);
		bt.setActionCommand("SNOOZE");
		
		JButton bt1 = new JButton();
		bt1.setContentAreaFilled(false);
		bt1.setBorderPainted(false);
		bt1.setIcon(new ImageIcon(dir+"open.png"));
		bt1.setPreferredSize(new Dimension(150,40));
		bt1.addActionListener(this);
		bt1.setActionCommand("OPEN");
		
		JButton bt2 = new JButton();
		bt2.setContentAreaFilled(false);
		bt2.setBorderPainted(false);
		bt2.setIcon(new ImageIcon(dir+"dismiss.png"));
		bt2.setPreferredSize(new Dimension(150,40));
		bt2.addActionListener(this);
		bt2.setActionCommand("DISMISS");
		
		
		
		font.add(emp);
		font.add(icon);
		font.add(subject);
		font.add(emp2);
		
		if(event.getType()!=1)
		{			
			font.add(bt1);
			font.add(bt2);
		}
		else
		{
			font.add(bt);
			font.add(bt2);
		}
		
		
		img.add(font);
		frame.add(img);
		frame.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) 
	{
		frame.dispose();
		
		if(arg0.getActionCommand().equals("OPEN"))
		{
			AddFrame fr = new AddFrame(event.getType(),event, cv);
		}
		else if(arg0.getActionCommand().equals("SNOOZE"))
			tk.snoozeEvent(event);
			
		
	}

}
